
var pgpromise = require( 'pg-promise' )()

const pgConfig = {
    user: 'postgres',
    password: '123456',
    database: 'postgres',                                                                                   
    host: '127.0.0.1',
    port: '5432',
    poolSize: 5,
}   

var db = pgpromise( pgConfig )

async function main(){

    var cameras = {
    "192.168.26.7": 12,
    "192.168.26.13": 9,
    "192.168.26.15": 10,
    "192.168.26.44": 11,
    "192.168.26.46": 13,
	"192.168.26.31": 15,
	"192.168.26.2": 16,
	"192.168.26.12": 18,
	"192.168.26.59": 19,
	"192.168.26.54": 20,
	"192.168.26.35": 22,
	"192.168.26.36": 23
    }

    try{
        await db.query( 'UPDATE protectors SET cameras = $2 WHERE mac = $1 ', ['123456789012',  cameras ]);
        var ret = await db.query( 'SELECT cameras from protectors WHERE mac = $1', ['123456789012' ]);
	console.log( ret );
    }
    catch( error ) {
        console.log( "update database error: ", error );
    }
}

main();
